07 / 22

What are endpoints in RTK Query?

In RTK Query, endpoints define the operations your application can perform with an API — such as fetching, creating, updating, or deleting data. Each endpoint describes how a specific request should be made and how RTK Query should cache or update the response.

Types of Endpoints
  1. 1

    Query endpoints: Used for fetching and reading data from an API. Defined using builder.query().

  2. 2

    Mutation endpoints: Used for creating, updating, or deleting data. Defined using builder.mutation().

Purpose of Endpoints
  1. 1

    Define the API routes and request configurations for each operation.

  2. 2

    Automatically generate React hooks like useGetUsersQuery or useAddUserMutation.

  3. 3

    Control caching, invalidation, and refetching behavior for specific data sets.

  4. 4

    Allow strong typing and automatic inference when using TypeScript.

Example: Defining Endpoints in createApi()

Endpoints are the core building blocks of RTK Query APIs, defining how your application interacts with backend services in a clean, declarative way.